<extend name="Layout/ins_page" />
<block name="content">
	{:W('PageHeader/simple',array('name'=>'业务权限分配'))}
	<div class="oprator-panel">
		<div class="split"></div>
		<a id="btn_save"  class="btn">保存</a>
	</div>
	<div class="row">
		<form id="form_data" method="post" action="">
			<div class="sub-sidebar">
				<table class="table table-bordered">
					<thead>
						<tr>
							<th></th>
							<th>名称</th>
						</tr>
					</thead>
					<tbody>
						<volist name="role_list" id="data">
							<tr id="{$data.id}">
								<td class="col-3 text-center x-checkbox">
								<input  type="checkbox" name="role_id[]" value="{$data.id}" />
								</td>
								<td>{$data.name}</td>
							</tr>
						</volist>
					</tbody>
				</table>
			</div>
			<div class="sub-content">
				<table class="table table-bordered">
					<thead>
						<tr>
							<th>&nbsp;</th>
							<th>名称</th>
							<th>备注</th>
						</tr>
					</thead>
					<tbody>
						<volist name="duty_list" id="data">
							<tr id="{$data.id}">
								<td class="col-3 text-center x-checkbox">
								<input type="checkbox" id="duty_{$data.id}" name="duty_list[]" value="{$data.id}"/>
								</td>
								<td class="col-10">{$data.name}</td>
								<td>{$data.remark}</td>
							</tr>
						</volist>
					</tbody>
				</table>
			</div>
		</form>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global'], function() {
			var $ = layui.jquery;

			var layer = layui.layer;

			set_return_url(null);

			$(".sub-sidebar  tr").click(function() {
				$(".sub-sidebar  tr").attr("class", "");
				$(this).attr("class", "active");
				$("#role_id").val($(this).attr("id"));
				send_ajax("{:U('get_duty_list')}", "role_id=" + $(this).attr("id"), function(data) {
					showdata(data);
				});
			});

			function showdata(result) {
				$("input[name='duty_list[]']").each(function() {
					$(this).prop('checked', false);
				});
				for (var s in result.data) {
					$("#duty_" + result.data[s].duty_id).prop('checked', true);
				}
			};

			//保存后关闭
			$('#btn_save').on('click', function() {
				send_form('form_data', '{:U("set_duty")}', '', function(ret) {
					if (ret.status == 1) {
						layer.msg(ret.info);
						location.reload(true);
					} else {
						layer.msg(ret.info);
						return false;
					}
				});
			});
		});

	</script>
</block>